<script>
	$(document).ready(function(){
		$('.entity_type').click(function(){
			var type = $(this).val();
			if(type == 1){
				$('#entity_service').show();
				$('#entity_product').hide();
			}else{
				$('#entity_service').hide();
				$('#entity_product').show();
			}
		});
	});
</script>
<div class="container_12"> 
    <div class="module">
        <h2><span><?php echo $_title; ?></span></h2>
        <div class="module-body">
            <div style="margin-top:13px;">
                <?php
                if(isset($errMsg)){?>
                    <span class="notification"><?php echo $_MESSESGE[$errMsg];?></span>
                <?php }?>
			</div>
                        
            <form name="admin_frm" id="admin_frm"  action="" method="post" enctype="multipart/form-data">
				 <form name="admin_frm" action="" method="post" enctype="multipart/form-data">
                <p>
                    <label>Name</label>
                    <div id="availability_info"></div>
					<input type="text" class="input-short check_availability" name="name" value="<?php echo $result['name'];?>" />
                    <!--  <span class="notification-input ni-correct">This is correct, thanks!</span> -->
                </p>
                <p>
                    <label>Entity Type</label>
                    <input type="radio" class="entity_type" name="entity_type" value="1" <?php print($result['entity_type']=='1' ? 'checked':'');?> /> Service Deal
                    <input type="radio" class="entity_type" name="entity_type" value="2" <?php print($result['entity_type']=='2' ? 'checked':'');?> /> Product Deal
                </p> 
                <p style="display:<?php echo $service_display;?>;" id="entity_service">
                    <label>Entity</label>
                    <select class="input-short" id="service" name="service">
                        <option value="">Select Service</option>
                        <?php
                        foreach($services as $key => $val){
                            $selected = ($val['id'] == $sid)?'selected':'';?>
                            <option value="<?php echo $val['id']; ?>" <?php echo $selected; ?>><?php echo $val['name']; ?></option>
                        <?php } ?>
                    </select>
                </p>
                <p style="display:<?php echo $product_display;?>; " id="entity_product">
                    <label>Entity</label>
                    <select class="input-short" id="product" name="product">
                        <option value="">Select Product</option>
                        <?php
                        foreach($products as $key => $val){
                            $selected = ($val['id'] == $pid)?'selected':'';?>
                            <option value="<?php echo $val['id']; ?>" <?php echo $selected; ?>><?php echo $val['name']; ?></option>
                        <?php } ?>
                    </select>
                </p>
                <p>
                    <label>Start Date</label>
                    <input name="start_date" type="text"  class="inputText" value="<?=$result['start_date']?>" size="10"/><a href="javascript:showCal('Calendar1')"><img src="<?php echo _SITE_ADMIN_URL_;?>images/calendar.jpg" alt="Click Here to Pick up the date" border="0" /></a>
                    <!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                </p>
                <p>
                    <label>End Date</label>
                    <input name="end_date" type="text"  class="inputText" value="<?=$result['end_date']?>" size="10"/><a href="javascript:showCal('Calendar2')"><img src="<?php echo _SITE_ADMIN_URL_;?>images/calendar.jpg" alt="Click Here to Pick up the date" border="0" /></a>
                    <!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                </p>

                <p>
                    <label>Discount</label>
                    <input type="text" class="input-short" name="discount" value="<?php echo $result['discount'];?>" />
                    <select class="input-short" name="discount_type">                                    
                        <option value="1" <?php if($result['discount_type']=='1'){echo 'selected';}?> >Flat</option>
                        <option value="2" <?php if($result['discount_type']=='2'){echo 'selected';}?> >Percent</option>
                    </select>
                    <!-- <span class="notification-input ni-error">Sorry, try again.</span> -->
                </p>
                
                <p>
                    <label>Upload Banner Image</label>
                    <input type="file" name="deal_image">
                </p>

				<fieldset>
					<input type="hidden" class="input-short" name="id" value="<?php echo $result['id'];?>" />
					<input class="submit-green" type="submit" name="submit" value="Submit" /> 
					<input class="submit-gray" type="button" value="Cancel" onclick="javascript: window.location='<?php echo _SITE_ADMIN_URL_?>'+'content/news_mng.php';" />
				</fieldset>
			</form>
		</div> <!-- End .module-body -->
	</div>  <!-- End .module -->
</div>
<div style="clear:both;"></div>

<script type="text/javascript">
    var root_path = '<?php echo _SITE_ADMIN_URL_?>';
	var table = 'deals';
	var field = 'name';
	
	jQuery.validator.addMethod(
        "selectServiceNone",
        function(value, element) {
            if (element.value == ""){
                return false;
            }
            else return true;
        },
        "Please select a service."
    );
    
    jQuery.validator.addMethod(
        "selectProductNone",
        function(value, element) {
            if (element.value == ""){
                return false;
            }
            else return true;
        },
        "Please select a product."
    );
    
    $().ready(function() {
        $("#admin_frm").validate({
            rules: {
                name: "required",
                service: {
                    selectServiceNone: true
                },
                product: {
                    selectProductNone: true
                },
                start_date: "required",
                end_date: "required",
                discount: "required"
            },
            messages: {
                name: "Please enter deal name",
                start_date: "Please enter deal start date",
                end_date: "Please enter deal end date",
                discount: "Please enter discount"
            }
        });
    });
</script> 
<script type="text/javascript" src="<?php echo _ADMIN_JS_; ?>check_availability.js"></script>